import SyntaxHighlighter from '@/components/SyntaxHighlighter'
import { useEffect } from 'react';

const arrs = [1, 2, 3, 4, 5, 56, 6, 4, 43, 3, 3, 5];

const code1 = `
  [1, 2, 3, 4, 5, 56, 6, 4, 43, 3, 3, 5];
`

const code2 = `
  const clearFn = () => {
    let result = []

    // 第一种
    // arrs.forEach(item => {
    //   if (result.indexOf(item) === -1) {
    //     result.push(item)
    //   }
    // })

    // 第二种
    result = [...new Set(arrs)]
    
    console.log('result', result)
  }
`

function ClearRepeat() {

  const clearFn = () => {
    let result = []

    // 第一种
    // arrs.forEach(item => {
    //   if (result.indexOf(item) === -1) {
    //     result.push(item)
    //   }
    // })

    // 第二种
    result = [...new Set(arrs)]
    
    console.log('result', result)
  }

  useEffect(() => {
    clearFn()
  }, [])

  return (
    <div>
      <p>将下列数据去重</p>
      <SyntaxHighlighter children={code1} />
      <p>代码逻辑如下：</p>
      <SyntaxHighlighter children={code2} />
    </div>
  )
}

export default ClearRepeat